<template>
    <div class="drug-consum">
        <div class="tree_icon">
            <el-icon style="float: right" @click="handleCloseDrugConsum">
                <close />
            </el-icon>
        </div>
        <br /><br />
        <div style="text-align: center">
            <el-input v-model="compState.filterText" :placeholder="placeholderFormatFun()"
                style="width: 90%; margin-bottom: 10px" :prefix-icon="Search"/>
        </div>
        <el-scrollbar height="390px">
            <el-tree ref="treeRef" class="filter-tree" :data="props.data" :props="defaultProps"
                @node-click="handleDrugNodeClick" :filter-node-method="filterNode" default-expand-all>
            </el-tree>
        </el-scrollbar>
    </div>
</template>

<script setup>
import { ref, reactive, watch } from 'vue'
import { Search } from '@element-plus/icons-vue'

const emit = defineEmits(['drugconsumNodeEmit', 'closeDrugConsumEmit'])
const props = defineProps({
    data: {
        type: Array,
        default: () => []
    }
})
const treeRef = ref()
const compState = reactive({
    filterText: ""
})
const defaultProps = {
    children: 'children', label: 'name'
}
// const { hospitalTreeRemoteVx } = setupMapState("HospVenuAmbuModule", ["hospitalTreeRemoteVx"])
// 监听输入框
watch(() => compState.filterText, (newV) => {
    // console.log(newV)
    treeRef.value.filter(newV)
})
// 过滤节点数据
const filterNode = (value, data) => {
    if (!value) return true;
    return data.name.includes(value);
};
const placeholderFormatFun = () => {
    let placeholder = "药品耗材不足医疗点搜索"
    return placeholder
}
const handleDrugNodeClick = (node) => {
    console.log(node)
    emit("drugconsumNodeEmit", node)
}
const handleCloseDrugConsum = () => {
    compState.filterText = ""
    emit('closeDrugConsumEmit')
}
</script>

<style scoped>
.tree_icon {
    margin: 5px;
}

.tree_icon:hover {
    color: #758bfd;
    cursor: pointer;
}
</style>